import React, { Component, PropTypes } from 'react';
import { connect } from 'dva';
import { Icon, Menu, Dropdown } from 'antd';
import { Link } from 'dva/router';
import styles from '../../routes/IndexPage.css';
import { getItem, inArray } from '../../utils/utils';
const MenuItemGroup = Menu.ItemGroup;
const permissionList = localStorage.getItem("permissions") ? JSON.parse(localStorage.getItem("permissions")) : {};
const data = permissionList.map(d => d);
class Slider extends Component {

    state = {
        current: '1',
        openKeys: [],
    }
    handleClick = (e) => {
        this.setState({ current: e.key });
    }

    onOpenChange = (openKeys) => {
        const state = this.state;
        const latestOpenKey = openKeys.find(key => !(state.openKeys.indexOf(key) > -1));
        const latestCloseKey = state.openKeys.find(key => !(openKeys.indexOf(key) > -1));

        let nextOpenKeys = [];
        if (latestOpenKey) {
            nextOpenKeys = this.getAncestorKeys(latestOpenKey).concat(latestOpenKey);
        }
        if (latestCloseKey) {
            nextOpenKeys = this.getAncestorKeys(latestCloseKey);
        }
        this.setState({ openKeys: nextOpenKeys });
    }
    getAncestorKeys = (key) => {
        const map = {
            sub3: ['sub2'],
        };
        return map[key] || [];
    }

    render() {

        return (
          <div className={"menu-slider-warp"}>
            <div className={"menu-slider"}>
                <Menu
                    theme='dark'
                    style={{ width: 220 }}
                    mode="inline"
                    inlineIndent="false"
                    openKeys={this.state.openKeys}
                    selectedKeys={[this.state.current]}
                    onOpenChange={this.onOpenChange}
                    onClick={this.handleClick}
                >
                    {inArray('sys', data) > -1 ? <Menu.SubMenu key='sys' title={(<span><i className="asset">&#xe613;</i><span>系统管理</span></span>)}>
                        {inArray('user', data) > -1 ?
                            <Menu.Item key='user'>
                                <Link to='/sys/user'><span><i className="asset">&#xe62a;</i><span>用户管理</span></span></Link>
                            </Menu.Item> : ''}
                        {inArray('role', data) > -1 ?
                            <Menu.Item key='role'>
                                <Link to='/sys/role'><span><i className="asset">&#xe695;</i><span>角色管理</span></span></Link>
                            </Menu.Item> : ''}
                        {inArray('dept', data) > -1 ?
                            <Menu.Item key='dept'>
                                <Link to='/sys/dept'><span><i className="asset">&#xe6a0;</i><span>组织结构</span></span></Link>
                            </Menu.Item> : ''}
                        {inArray('log', data) > -1 ?
                            <Menu.Item key='log'>
                                <Link to='/sys/log'><span><i className="asset">&#xe65f;</i><span>日志查询</span></span></Link>
                            </Menu.Item> : ''}
                    </Menu.SubMenu> : ''}

                    {inArray('basic', data) > -1 ? <Menu.SubMenu key='basic' title={(<span><i className="asset">&#xe618;</i><span>基础配置</span></span>)}>
                        {inArray('assetType', data) > -1 ?
                            <Menu.Item key='assetType'>
                                <Link to='/basic/assetType'><span><i className="asset">&#xe651;</i><span>资产分类</span></span></Link>
                            </Menu.Item> : ''}
                        {inArray('assetAttr', data) > -1 ?
                            <Menu.Item key='assetAttr'>
                                <Link to='/basic/assetAttr'><span><i className="asset">&#xe706;</i><span>资产属性</span></span></Link>
                            </Menu.Item> : ''}
                        {inArray('assetBrand', data) > -1 ?
                            <Menu.Item key='assetBrand'>
                                <Link to='/basic/assetBrand'><span><i className="asset">&#xe607;</i><span>品牌管理</span></span></Link>
                            </Menu.Item> : ''}
                        {inArray('assetModel', data) > -1 ?
                            <Menu.Item key='assetModel'>
                                <Link to='/basic/assetModel'><span><i className="asset">&#xe600;</i><span>型号管理</span></span></Link>
                            </Menu.Item> : ''}
                        {inArray('dataCenter', data) > -1 ?
                            <Menu.Item key='dataCenter'>
                                <Link to='/basic/dataCenter'><span><i className="asset">&#xe801;</i><span>数据中心</span></span></Link>
                            </Menu.Item> : ''}
                         {inArray('tRoom', data) > -1 ?
                            <Menu.Item key='tRoom'>
                                <Link to='/basic/tRoom'><span><i className="asset">&#xe752;</i><span>机房管理</span></span></Link>
                            </Menu.Item> : ''}
                        {inArray('cabinet', data) > -1 ?
                            <Menu.Item key="cabinet">
                                <Link to='cabinet'><span><i className="asset">&#xe682;</i><span>机柜管理</span></span></Link>
                            </Menu.Item> : ''}
                        {inArray('cabinetGroup', data) > -1 ?
                            <Menu.Item key="cabinetGroup">
                                <Link to='cabinetGroup'><span><i className="asset">&#xe656;</i><span>机柜组管理</span></span></Link>
                            </Menu.Item> : ''}
                        {inArray('storeRoom', data) > -1 ?
                            <Menu.Item key='storeRoom'>
                                <Link to='/basic/storeRoom'><span><i className="asset">&#xe615;</i><span>库房管理</span></span></Link>
                            </Menu.Item> : ''}

                    </Menu.SubMenu> : ''}

                     {inArray('contract', data) > -1 ?
                            <Menu.Item key="contract">
                                <Link to='contract'><span><i className="asset">&#xe673;</i><span>合同管理</span></span></Link>
                            </Menu.Item> : ''}


                     {inArray('equipment', data) > -1 ?
                        <Menu.SubMenu key='equipment' title={(<span><i className="asset">&#xe627;</i><span>设备管理</span></span>)}>
                            {inArray('preset', data) > -1 ?
                                <Menu.Item key="preset">
                                    <Link to='equipment/preset'><span><i className="asset">&#xe6b6;</i><span>预置管理</span></span></Link>
                                </Menu.Item> : ''}
                            {inArray('arrival', data) > -1 ?
                                <Menu.Item key="arrival">
                                    <Link to='equipment/arrival'><span><i className="asset">&#xe8e5;</i><span>到货验收</span></span></Link>
                                </Menu.Item> : ''}
                            {inArray('instock', data) > -1 ?
                                 <Menu.Item key="instock">
                                    <Link to='instock'><span><i className="asset">&#xe8e5;</i><span>设备入库</span></span></Link>
                                </Menu.Item>  : ''}
                            {inArray('up', data) > -1 ?
                                <Menu.Item key="up">
                                    <Link to='shelf/up'><span><i className="asset">&#xe6c4;</i><span>设备上架</span></span></Link>
                                </Menu.Item> : ''}
                            {inArray('down', data) > -1 ?
                                <Menu.Item key="down">
                                    <Link to='shelf/down'><span><i className="asset">&#xe610;</i><span>设备下架</span></span></Link>
                                </Menu.Item> : ''}
                            {inArray('apply', data) > -1 ?
                                <Menu.Item key="apply">
                                    <Link to='using/apply'><span><i className="asset">&#xe60e;</i><span>领用申请</span></span></Link>
                                </Menu.Item> : ''}
                            {inArray('distribution', data) > -1 ?
                                <Menu.Item key="distribution">
                                    <Link to='using/distribution'><span><i className="asset">&#xe65e;</i><span>领用分配</span></span></Link>
                                </Menu.Item> : ''}
                            {inArray('qy', data) > -1 ?
                                <Menu.Item key="qy">
                                    <Link to='transfer'><span><i className="asset">&#xe6b2;</i><span>设备迁移</span></span></Link>
                                </Menu.Item> : ''}
                            {inArray('borrow', data) > -1 ?
                                <Menu.Item key="borrow">
                                    <Link to='borrow/borrow'><span><i className="asset">&#xe619;</i><span>借用归还</span></span></Link>
                                </Menu.Item> : ''}
                            {inArray('repair', data) > -1 ?
                                <Menu.Item key="repair">
                                    <Link to='repair'><span><i className="asset">&#xe63a;</i><span>设备维修</span></span></Link>
                                </Menu.Item> : ''}
                             {inArray('bf', data) > -1 ?
                                <Menu.Item key="bf">
                                    <Link to='scrap'><span><i className="asset">&#xe71a;</i><span>设备报废</span></span></Link>
                                </Menu.Item> : ''}
                            {inArray('out', data) > -1 ?
                                <Menu.Item key="out">
                                    <Link to='out'><span><i className="asset">&#xe61d;</i><span>库房出库</span></span></Link>
                                </Menu.Item> : ''}
                        </Menu.SubMenu> : ''}

                      {inArray('resourceManage', data) > -1 ?
                        <Menu.SubMenu key='resourceManage' title={(<span><i className="asset">&#xe65d;</i><span>资源管理</span></span>)}>
                            {inArray('ipParam', data) > -1 ?
                                <Menu.Item key='ipParam'>
                                    <Link to='ipParam'><span><i className="asset">&#xe632;</i><span>IP参数管理</span></span></Link>
                                </Menu.Item> : ''}
                            {inArray('rg', data) > -1 ?
                                <Menu.Item key='rg'>
                                    <Link to='resourceGroup'><span><i className="asset">&#xe6bf;</i><span>资源组管理</span></span></Link>
                                </Menu.Item> : ''}
                            {inArray('resource', data) > -1 ?
                                <Menu.Item key='resource'>
                                    <Link to='resource'><span><i className="asset">&#xe722;</i><span>资源管理</span></span></Link>
                                </Menu.Item> : ''}
                        </Menu.SubMenu> : ''}


                     {inArray('assetSearch', data) > -1 ?
                        <Menu.SubMenu key='assetSearch' title={(<span><i className="asset">&#xe6f0;</i><span>资产查询</span></span>)}>
                            {inArray('maintain', data) > -1 ?
                                <Menu.Item key='maintain'>
                                    <Link to='asset/maintain'><span><i className="asset">&#xe60f;</i><span>资产卡片</span></span></Link>
                                </Menu.Item> : ''}
                            {inArray('advancedQuery', data) > -1 ?
                                <Menu.Item key='advancedQuery'>
                                    <Link to='asset/dynamicSearch'><span><i className="asset">&#xe6f0;</i><span>资产查询</span></span></Link>
                                </Menu.Item>:''}
                            {inArray('topology', data) > -1 ?
                                <Menu.Item key='topology'>
                                    <Link to='topology'><span><i className="asset">&#xe83d;</i><span>2D拓扑</span></span></Link>
                                </Menu.Item>:''}
                            {inArray('assetRecord', data) > -1 ?
                                <Menu.Item key='assetRecord'>
                                    <Link to='assetRecord'><span><i className="asset">&#xe61c;</i><span>生命周期</span></span></Link>
                                </Menu.Item> : ''}
                        </Menu.SubMenu> : ''}

                     {inArray('inspectionCheck', data) > -1 ?
                        <Menu.SubMenu key='inspectionCheck' title={(<span><i className="asset">&#xe723;</i><span>巡检盘点</span></span>)}>
                            {inArray('inventory', data) > -1 ?
                                <Menu.Item key='inventory'>
                                    <Link to='inventory'><span><i className="asset">&#xe611;</i><span>盘点计划</span></span></Link>
                                </Menu.Item> : ''}
                            {inArray('patrolPlan', data) > -1 ?
                                <Menu.Item key='patrolPlan'>
                                    <Link to='patrolPlan'><span><i className="asset">&#xe68f;</i><span>巡检计划</span></span></Link>
                                </Menu.Item> : ''}
                            {inArray('inventorySheet', data) > -1 ?
                                <Menu.Item key='inventorySheet'>
                                    <Link to='inventorySheet'><span><i className="asset">&#xe61b;</i><span>盘点查询</span></span></Link>
                                </Menu.Item> : ''}
                            {inArray('patrol', data) > -1 ?
                                <Menu.Item key='patrol'>
                                    <Link to='patrol'><span><i className="asset">&#xe63f;</i><span>巡检查询</span></span></Link>
                                </Menu.Item> : ''}
                        </Menu.SubMenu> : ''}


                    {inArray('ledger', data) > -1 ?
                        <Menu.SubMenu key='ledger' title={(<span><i className="asset">&#xe608;</i><span>统计台账</span></span>)}>
                            {inArray('typeLedger', data) > -1 ?
                                <Menu.Item key='typeLedger'>
                                    <Link to='ledger/assetTypeLedger'><span><i className="asset">&#xe651;</i><span>类型台账</span></span></Link>
                                </Menu.Item> : ''}
                            {inArray('statusLedger', data) > -1 ?
                                <Menu.Item key='statusLedger'>
                                    <Link to='ledger/assetStatus'><span><i className="asset">&#xe629;</i><span>状态台账</span></span></Link>
                                </Menu.Item> : ''}
                            {inArray('brandLedger', data) > -1 ?
                                <Menu.Item key='brandLedger'>
                                    <Link to='ledger/assetBrandLedger'><span><i className="asset">&#xe607;</i><span>品牌台账</span></span></Link>
                                </Menu.Item> : ''}
                            {inArray('departLedger', data) > -1 ?
                                <Menu.Item key='departLedger'>
                                    <Link to='ledger/assetDepart'><span><i className="asset">&#xe6cf;</i><span>部门台账</span></span></Link>
                                </Menu.Item> : ''}
                            {inArray('serviceLifeLedger', data) > -1 ?
                                <Menu.Item key='serviceLifeLedger'>
                                    <Link to='ledger/serviceLifeLedger'><span><i className="asset">&#xe6cf;</i><span>使用年限统计</span></span></Link>
                                </Menu.Item> : ''}
                            {inArray('cabinetCount', data) > -1 ?
                                <Menu.Item key='cabinetCount'>
                                    <Link to='ledger/cabinetCount'><span><i className="asset">&#xe6cf;</i><span>机柜容量统计</span></span></Link>
                                </Menu.Item> : ''}

                        </Menu.SubMenu> : ''}
                       {inArray('report', data) > -1 ?
                         <Menu.SubMenu key='report' title={(<span><i className="asset">&#xe627;</i><span>报表管理</span></span>)}>
                            {inArray('reportPlan', data) > -1 ?
                                <Menu.Item key="reportPlan">
                                    <Link to='reportPlan'><span><i className="asset">&#xe6b6;</i><span>报表计划</span></span></Link>
                                </Menu.Item>  : ''}
                            {inArray('reportList', data) > -1 ?
                                <Menu.Item key="reportList">
                                    <Link to='reportList'><span><i className="asset">&#xe6b6;</i><span>报表查看</span></span></Link>
                                </Menu.Item>  : ''}
                        </Menu.SubMenu>: ''}

                    {inArray('hardware', data) > -1 ?
                        <Menu.Item key='hardware'>
                           <Link to='hard/hardware'><span><i className="asset">&#xe6b6;</i><span>硬件管理</span></span></Link>
                        </Menu.Item> : ''}

                    {inArray('infoSearch', data) > -1 ?
                        <Menu.SubMenu key='infoSearch' title={(<span><i className="asset">&#xe769;</i><span>信息查询</span></span>)}>
                            {inArray('alarm', data) > -1 ?
                                <Menu.Item key='alarm'>
                                    <Link to='alarm'><span><i className="asset">&#xe694;</i><span>报警查询</span></span></Link>
                                </Menu.Item> : ''}
                            {inArray('maintenant', data) > -1 ?
                                <Menu.Item key='maintenant'>
                                    <Link to='maintenant'><span><i className="asset">&#xe61c;</i><span>维保到期提醒</span></span></Link>
                                </Menu.Item> : ''}
                            {inArray('temperature', data) > -1 ?
                               <Menu.Item key="temperature">
                                    <Link to='temperature'><span><i className="asset">&#xe61e;</i><span>机柜温湿度</span></span></Link>
                                </Menu.Item> : ''}
                        </Menu.SubMenu> : ''}
                        {inArray('space', data) > -1 ?
                                <Menu.Item key='sapce'>
                                    <Link to='space/space'><span><i className="asset">&#xe6b6;</i><span>空间管理</span></span></Link>
                                </Menu.Item> : ''
                          }
                </Menu>
                </div>
            </div>
        );
    }
}


export default Slider;
